package com.qf.fmw.controller;


import com.qf.fmw.entity.vo.RespResult;
import com.qf.fmw.service.OrderService;
import com.qf.fmw.service.impl.OrderServiceImpl;
import com.qf.fmw.servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/OrderController")
public class OrderController extends BaseServlet {
    private OrderService orderService =new OrderServiceImpl();

    // 展示订单列表
    protected RespResult getAllOrders(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return orderService.showAllOrders();
    }

    // 根据用户名或者订单状态搜索订单
    protected RespResult searchOrders(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return orderService.searchOrders(request.getParameter("userName"), Integer.parseInt(request.getParameter("orderState")));
    }

    // 更新订单状态
    protected RespResult updateOrderStatus(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int orderId = Integer.parseInt(request.getParameter("orderId"));
        int orderState = Integer.parseInt(request.getParameter("orderState"));
        return orderService.updateOrderStatus(orderId, orderState);
    }
}

